//////////////////////////////////////////////////////////////////////////////////
//
//	Psychostats Say Command
//		- Version 1.1
//		- 04.18.2008
//		- diamond-optic
//
//////////////////////////////////////////////////////////////////////////////////
//
// Information:
//
// 	- View psychostats page in MOTD window when you type /stats, /rank, /top10, /top15
//	- Optional on-join message announcing commands
//
// CVARs: 
//
//	amx_psychostats_url "http://" 	//Put your pstats address here
//					//example: http://psychostats.teamcdrive.com/stats/
//
//	amx_psychostats_joinmsg "1"	//Turn ON(1)/OFF(0) on-join message
//	amx_psychostats_delay "60"	//Seconds after client connects to show on-join msg
//
// Changelog:
//
//	- 07.16.2006 Version 1.0
//		Initial Release
//
//	- 07.24.2006 Version 1.0b
//		Added title to MOTD window
//
//	- 12.17.2006 Version 1.1
//		Added some new stuff...
//		  * /stats shows main pstats index page
//		  * /rank shows player's pstats page
//		  * /top10 & /top15 shows top 10 motd.php
//
//	- 04.18.2008 Version 1.1 (re-release)
//		Public CVAR
//
//////////////////////////////////////////////////////////////////////////////////


#include <amxmodx>

new VERSION[] = "1.1"
new SVERSION[] = "v1.1 by diamond-optic (www.AvaMods.com)"

new p_address, p_join, p_delay

public plugin_init()
{
	register_plugin("Psychostats Say Command",VERSION,"diamond-optic")
	register_cvar("amx_psychostats_stats",SVERSION,FCVAR_SERVER|FCVAR_SPONLY)
	
	p_address = register_cvar("amx_psychostats_url","http://")
	p_join = register_cvar("amx_psychostats_joinmsg","1")
	p_delay = register_cvar("amx_psychostats_delay","60")
	
	register_clcmd("say /stats","ShowStats",0,"Show psychostats")
	register_clcmd("say_team /stats","ShowStats",0,"Show psychostats")
	
	register_clcmd("say /rank","ShowRank",0,"Show psychostats rank")
	register_clcmd("say_team /rank","ShowRank",0,"Show psychostats rank")
	
	register_clcmd("say /top10","ShowTop10",0,"Show psychostats top 10")
	register_clcmd("say_team /top10","ShowTop10",0,"Show psychostats top 10")
	register_clcmd("say /top15","ShowTop10",0,"Show psychostats top 10")
	register_clcmd("say_team /top15","ShowTop10",0,"Show psychostats top 10")
}

public client_putinserver(id)
	if(!is_user_bot(id) && is_user_connected(id) && get_pcvar_num(p_join)) 
		set_task(get_pcvar_float(p_delay),"ShowMsg",id)

public ShowMsg(id)
	if(!is_user_bot(id) && is_user_connected(id) && get_pcvar_num(p_join)) 
		client_print(id, print_chat, "To view psychostats, type /stats, /rank, /top10 in the chat...")

public ShowStats(id)	//Show main pstats index page
{	
	if(!is_user_bot(id) && is_user_connected(id))
		{
		new stats_address[256],motd[512]
		get_pcvar_string(p_address,stats_address,255)
		
		formatex(motd,511,"<html><frameset><frame src=^"%s^" name=^"frame_main^" /></frameset></html>",stats_address)
	
		show_motd(id,motd,"Psychostats")
		}
}

public ShowRank(id)	//Show the calling playing his/her pstats page
{	
	if(!is_user_bot(id) && is_user_connected(id))
		{
		new stats_address[256],motd[512],authid[32]
		get_pcvar_string(p_address,stats_address,255)
		get_user_authid(id,authid,31)
				
		formatex(motd,511,"<html><frameset><frame src=^"%sindex.php?search=%s^" name=^"frame_main^" /></frameset></html>",stats_address,authid)
	
		show_motd(id,motd,"Psychostats")
		}
}

public ShowTop10(id)	//Show top10 motd.php
{	
	if(!is_user_bot(id) && is_user_connected(id))
		{
		new stats_address[256],motd[512]
		get_pcvar_string(p_address,stats_address,255)
		
		formatex(motd,511,"<html><frameset><frame src=^"%smotd.php^" name=^"frame_main^" /></frameset></html>",stats_address)
	
		show_motd(id,motd,"Psychostats")
		}
}
